#!/usr/bin/bash

use_pbc_runner=$1
extra_flags=$2

params="--progress=verbose --exit-after-n-failures=0 -j16"
if [[ ${use_pbc_runner} == true ]]; then
  params+=" --json-test-results=mjsunit.be.114.release.result.json --pbc-runner=${PBC_RUNNER}"
  find ./test/mjsunit/ -name "*.pbc" -delete
else
  params+=" --json-test-results=mjsunit.be.release.result.json"
fi

echo "_______________extra_flags for mjsunit:${extra_flags}"
 
host=`uname -a`
if [[ ${host} == *"aarch64"* ]]; then
  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`/out/arm64.release-check
  time ./tools/run-tests.py --outdir=out/arm64.release-check mjsunit --extra-flags="--use-pbc --disable-copyable-pbc ${extra_flags} " ${params}
else
  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`/out/x64.release-check
  time ./tools/run-tests.py --outdir=out/x64.release-check mjsunit --extra-flags="--use-pbc --disable-copyable-pbc ${extra_flags} " ${params}
fi

echo "----------  python3 ./CI/test-result-filter-ir.py mjsunit.be.release.result.json mjsunit----------"
if [[ ${use_pbc_runner} == true ]]; then
  echo "mjsunit test use_pbc_runner not support"
else
  python3 ./CI/test-result-filter-ir.py mjsunit.be.release.result.json mjsunit
fi
exit $?